package com.example.littleSpider.myapplication.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.base.BaseActivity;
import com.example.littleSpider.myapplication.fragment.findJob.FindMasterFragment;
import com.example.littleSpider.myapplication.fragment.findJob.MineFragment;
import com.example.littleSpider.myapplication.fragment.findJob.RecruitInfoFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.OnClick;

/**
 * Created by aduser on 2017/12/7.
 */

public class FindJobActivity extends BaseActivity {

    FragmentManager manager;

    List<Fragment> fragmentList = new ArrayList<>();
    RecruitInfoFragment fragmentOne = new RecruitInfoFragment();
    FindMasterFragment fragmentTwo = new FindMasterFragment();
    MineFragment fragmentThree = new MineFragment();

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_find_job;
    }

    @Override
    protected void initView() {
        fragmentList.add(fragmentOne);
        fragmentList.add(fragmentTwo);
        fragmentList.add(fragmentThree);
        manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add(R.id.fragment, fragmentList.get(0));
        transaction.commit();
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.rl_go_back)
    public void goBack(){
        finish();
    }

    @OnClick({R.id.rbn_one, R.id.rbn_two, R.id.rbn_three})
    public void bottomButtons(View view){
        switch (view.getId()){
            case R.id.rbn_one: //招工信息
                changePage(0);
                break;
            case R.id.rbn_two: //找师傅
                changePage(1);
                break;
            case R.id.rbn_three: //我的
                changePage(2);
                break;
            default:
                break;
        }
    }

    private void changePage(int pageNum){
        Fragment currentFragment = fragmentList.get(pageNum);
        FragmentTransaction transaction = manager.beginTransaction();
        for (int i = 0; i < fragmentList.size(); i++){
            if (fragmentList.get(i).isAdded()){
                transaction.hide(fragmentList.get(i));
            }
        }
        if (!currentFragment.isAdded()){
            transaction.add(R.id.fragment, currentFragment);
        }
        transaction.show(currentFragment);
        transaction.commit();
    }
}
